#include <iostream>
#include <queue>

using namespace std;
using ll=long long;
const int N=1e5+10;

int a[N];
int main()
{
	int n,k;
	cin>>n>>k;
	ll ret=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		ret+=a[i];
	}
	priority_queue<int> q;
	for(int i=n-1;i>=k;i--)
	{
		q.push(a[i]);
		if(i%k==0)
		{
			ret-=q.top();
			q.pop();
		}
	}
	cout<<ret<<endl;


	return 0;
}
